<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_template/main.c Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css" />
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="alias.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="alias.js"></script>

<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>


<script type="text/javascript">
  jQuery(document).ready(function () {
    if(gref){ // Number all _img and _table classes
      gref();
    }
  });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">nRF51822 BLE SDK
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('nrf6310__nrf2752_2ble_2ble__app__template_2main_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">S110_nRF51822/Board/nrf6310_nrf2752/ble/ble_app_template/main.c</div>  </div>
</div>
<div class="contents">
<a href="nrf6310__nrf2752_2ble_2ble__app__template_2main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved.</span>
<a name="l00002"></a>00002 <span class="comment"> *</span>
<a name="l00003"></a>00003 <span class="comment"> * The information contained herein is confidential property of Nordic</span>
<a name="l00004"></a>00004 <span class="comment"> * Semiconductor ASA.Terms and conditions of usage are described in detail</span>
<a name="l00005"></a>00005 <span class="comment"> * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.</span>
<a name="l00006"></a>00006 <span class="comment"> *</span>
<a name="l00007"></a>00007 <span class="comment"> * Licensees are granted free, non-transferable use of the information. NO</span>
<a name="l00008"></a>00008 <span class="comment"> * WARRANTY of ANY KIND is provided. This heading must NOT be removed from</span>
<a name="l00009"></a>00009 <span class="comment"> * the file.</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * $$</span>
<a name="l00012"></a>00012 <span class="comment"> */</span>
<a name="l00013"></a>00013 
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;stdint.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;string.h&gt;</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="nordic__common_8h.html" title="Common defines and macros for firmware developed by Nordic Semiconductor.">nordic_common.h</a>&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;nrf.h&quot;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;<a class="code" href="nrf__assert_8h.html" title="Utilities for verifying program logic.">nrf_assert.h</a>&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;nrf_error.h&quot;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;nrf_gpio.h&quot;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;nrf51_bitfields.h&quot;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;ble.h&quot;</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include &quot;ble_hci.h&quot;</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include &quot;<a class="code" href="ble__srv__common_8h.html">ble_srv_common.h</a>&quot;</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include &quot;<a class="code" href="ble__advdata_8h.html">ble_advdata.h</a>&quot;</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include &quot;<a class="code" href="ble__conn__params_8h.html">ble_conn_params.h</a>&quot;</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include &quot;<a class="code" href="ble__nrf6310__pins_8h.html">ble_nrf6310_pins.h</a>&quot;</span>
<a name="l00041"></a>00041 <span class="preprocessor">#include &quot;<a class="code" href="app__scheduler_8h.html">app_scheduler.h</a>&quot;</span>
<a name="l00042"></a>00042 <span class="preprocessor">#include &quot;<a class="code" href="ble__stack__handler_8h.html">ble_stack_handler.h</a>&quot;</span>
<a name="l00043"></a>00043 <span class="preprocessor">#include &quot;<a class="code" href="app__timer_8h.html">app_timer.h</a>&quot;</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 
<a name="l00046"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">00046</a> <span class="preprocessor">#define DEVICE_NAME                     &quot;NORDIC_TEMPLATE&quot;                           </span>
<a name="l00048"></a><a class="code" href="group__ble__sdk__app__template__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">00048</a> <span class="preprocessor">#define APP_ADV_INTERVAL                64                                          </span>
<a name="l00049"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaf58371bad8e1be8e2323df60379ed2df">00049</a> <span class="preprocessor">#define APP_ADV_TIMEOUT_IN_SECONDS      180                                         </span>
<a name="l00051"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga95196d5d0f40cf195a6001955d6d98cf">00051</a> <span class="preprocessor">#define MIN_CONN_INTERVAL               ((1 * 800) / 2)                             </span>
<a name="l00052"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga7d868ed8adb7d475b463fd8855907a18">00052</a> <span class="preprocessor">#define MAX_CONN_INTERVAL               (1 * 800)                                   </span>
<a name="l00053"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga0c921a874ac37870fc1516ce66cd228a">00053</a> <span class="preprocessor">#define SLAVE_LATENCY                   0                                           </span>
<a name="l00054"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga799412c2b531ca347e13611e6e7523b9">00054</a> <span class="preprocessor">#define CONN_SUP_TIMEOUT                (4 * 100)                                   </span>
<a name="l00055"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">00055</a> <span class="preprocessor">#define FIRST_CONN_PARAMS_UPDATE_DELAY  (20 * 1000)                                 </span>
<a name="l00056"></a><a class="code" href="group__ble__sdk__app__template__main.html#gadf85796ef07632ed27e0bce9509d9245">00056</a> <span class="preprocessor">#define NEXT_CONN_PARAMS_UPDATE_DELAY   (5 * 1000)                                  </span>
<a name="l00057"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">00057</a> <span class="preprocessor">#define MAX_CONN_PARAMS_UPDATE_COUNT    3                                           </span>
<a name="l00059"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga7c1fffb0f865552108560d4c63b32db1">00059</a> <span class="preprocessor">#define SEC_PARAM_TIMEOUT               60                                          </span>
<a name="l00060"></a><a class="code" href="group__ble__sdk__app__template__main.html#gacbf03a82593c273743a5a80a1119b851">00060</a> <span class="preprocessor">#define SEC_PARAM_BOND                  1                                           </span>
<a name="l00061"></a><a class="code" href="group__ble__sdk__app__template__main.html#gab6831ebe113f8afe970326b7742b5947">00061</a> <span class="preprocessor">#define SEC_PARAM_MITM                  0                                           </span>
<a name="l00062"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga42df85b3a4083cdc614d9111d580d98f">00062</a> <span class="preprocessor">#define SEC_PARAM_IO_CAPABILITIES       BLE_GAP_IO_CAPS_NONE                        </span>
<a name="l00063"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">00063</a> <span class="preprocessor">#define SEC_PARAM_OOB                   0                                           </span>
<a name="l00064"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">00064</a> <span class="preprocessor">#define SEC_PARAM_MIN_KEY_SIZE          7                                           </span>
<a name="l00065"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaf2cd1595de153ea1d6d843619a1a7707">00065</a> <span class="preprocessor">#define SEC_PARAM_MAX_KEY_SIZE          16                                          </span>
<a name="l00067"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">00067</a> <span class="preprocessor">static ble_gap_sec_params_t             s_sec_params;                               </span>
<a name="l00068"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">00068</a> <span class="preprocessor">static uint16_t                         s_conn_handle = BLE_CONN_HANDLE_INVALID;    </span>
<a name="l00078"></a><a class="code" href="group__ble__sdk__app__template__main.html#gadec561788a76b8a63ad9663625a25d78">00078</a> <span class="preprocessor">void assert_nrf_callback(uint16_t line_num, const uint8_t * file_name)</span>
<a name="l00079"></a>00079 <span class="preprocessor"></span>{
<a name="l00080"></a>00080     <span class="comment">// Copying parameters to static variables because parameters are not accessible in debugger</span>
<a name="l00081"></a>00081     <span class="keyword">static</span> <span class="keyword">volatile</span> uint8_t  s_file_name[128];
<a name="l00082"></a>00082     <span class="keyword">static</span> <span class="keyword">volatile</span> uint16_t s_line_num;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084     strcpy((<span class="keywordtype">char</span> *)s_file_name, (<span class="keyword">const</span> <span class="keywordtype">char</span> *)file_name);
<a name="l00085"></a>00085     s_line_num = line_num;
<a name="l00086"></a>00086     UNUSED_VARIABLE(s_file_name);
<a name="l00087"></a>00087     UNUSED_VARIABLE(s_line_num);
<a name="l00088"></a>00088     
<a name="l00089"></a>00089     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ASSERT_LED_PIN_NO);
<a name="l00090"></a>00090 
<a name="l00091"></a>00091     <span class="keywordflow">for</span> (;;)
<a name="l00092"></a>00092     {
<a name="l00093"></a>00093         <span class="comment">// Loop forever. On assert, the system can only recover on reset</span>
<a name="l00094"></a>00094     }
<a name="l00095"></a>00095 }
<a name="l00096"></a>00096 
<a name="l00097"></a>00097 
<a name="l00105"></a>00105 <span class="comment">/*</span>
<a name="l00106"></a>00106 <span class="comment">// YOUR_JOB: Uncomment this function and make it handle error situations sent back to your </span>
<a name="l00107"></a>00107 <span class="comment">//           application by the services it uses.</span>
<a name="l00108"></a>00108 <span class="comment">static void service_error_handler(uint32_t nrf_error)</span>
<a name="l00109"></a>00109 <span class="comment">{</span>
<a name="l00110"></a>00110 <span class="comment">    ASSERT(false);</span>
<a name="l00111"></a>00111 <span class="comment">} */</span>
<a name="l00112"></a>00112 
<a name="l00113"></a>00113 
<a name="l00118"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga0892e076b365fc49b55bd0f90ab09222">00118</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>(<span class="keywordtype">void</span>)
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ADVERTISING_LED_PIN_NO);
<a name="l00121"></a>00121     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(CONNECTED_LED_PIN_NO);
<a name="l00122"></a>00122     <a class="code" href="group__ble__sdk__lib__util.html#ga3f8d3d1b629cf9a61a86886059987e6a" title="Configure a PIN to be used as a LED.">GPIO_LED_CONFIG</a>(ASSERT_LED_PIN_NO);
<a name="l00123"></a>00123     
<a name="l00124"></a>00124     <span class="comment">// YOUR_JOB: Add additional LED initialiazations if needed.</span>
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127 
<a name="l00132"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga09658aaa0774820d8f25249d551bc283">00132</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>(<span class="keywordtype">void</span>)
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134     uint32_t err_code;
<a name="l00135"></a>00135     
<a name="l00136"></a>00136     <span class="comment">// Initialize timer module, making it use the scheduler</span>
<a name="l00137"></a>00137     err_code = <a class="code" href="group__app__timer.html#ga4e1da5a2f64ee78ee97f7422ea97e439" title="Initializes the timer module.">app_timer_init</a>(<a class="code" href="group__app__scheduler.html#gad09181e10ae224ca354b5e650b5e3a0a" title="Schedules a timer event.">app_sched_timer_event_schedule</a>);
<a name="l00138"></a>00138     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00139"></a>00139     {
<a name="l00140"></a>00140         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00141"></a>00141     }
<a name="l00142"></a>00142 }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 
<a name="l00150"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga1004973353f351806e42896c491a5ab2">00150</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00151"></a>00151 {
<a name="l00152"></a>00152     uint32_t                err_code;
<a name="l00153"></a>00153     <a class="code" href="structble__gap__conn__params__t.html" title="GAP connection parameters.">ble_gap_conn_params_t</a>   gap_conn_params;
<a name="l00154"></a>00154     <a class="code" href="structble__gap__conn__sec__mode__t.html" title="GAP link requirements.">ble_gap_conn_sec_mode_t</a> sec_mode;
<a name="l00155"></a>00155 
<a name="l00156"></a>00156     <a class="code" href="group___b_l_e___g_a_p___c_o_n_n___s_e_c___m_o_d_e___s_e_t___m_a_c_r_o_s.html#ga2abd1c711d49a4d4b1ab9bf27cafffbb" title="Set sec_mode pointed to by ptr to require no protection, open link.">BLE_GAP_CONN_SEC_MODE_SET_OPEN</a>(&amp;sec_mode);
<a name="l00157"></a>00157     
<a name="l00158"></a>00158     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga7d665aa56f8d248b8779a6cf170e2052" title="Set GAP device name.">ble_gap_device_name_set</a>(&amp;sec_mode, <a class="code" href="group__ble__sdk__app__template__main.html#ga5f5a2c9450ebc584b4fe743c6b1a280b">DEVICE_NAME</a>);
<a name="l00159"></a>00159     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00160"></a>00160     {
<a name="l00161"></a>00161         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00162"></a>00162     }
<a name="l00163"></a>00163 
<a name="l00164"></a>00164     <span class="comment">/* YOUR_JOB: Use an appearance value matching the application&#39;s use case.</span>
<a name="l00165"></a>00165 <span class="comment">    err_code = ble_gap_appearance_set(BLE_APPEARANCE_);</span>
<a name="l00166"></a>00166 <span class="comment">    if (err_code != NRF_SUCCESS)</span>
<a name="l00167"></a>00167 <span class="comment">    {</span>
<a name="l00168"></a>00168 <span class="comment">        ASSERT(false);</span>
<a name="l00169"></a>00169 <span class="comment">    }*/</span>
<a name="l00170"></a>00170     
<a name="l00171"></a>00171     memset(&amp;gap_conn_params, 0, <span class="keyword">sizeof</span>(gap_conn_params));
<a name="l00172"></a>00172 
<a name="l00173"></a>00173     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#ac927a642ee2203f875fcce1eabb5fa64">min_conn_interval</a> = <a class="code" href="group__ble__sdk__app__template__main.html#ga95196d5d0f40cf195a6001955d6d98cf">MIN_CONN_INTERVAL</a>;
<a name="l00174"></a>00174     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a0aec1884f340406a5194b772da017d7b">max_conn_interval</a> = <a class="code" href="group__ble__sdk__app__template__main.html#ga7d868ed8adb7d475b463fd8855907a18">MAX_CONN_INTERVAL</a>;
<a name="l00175"></a>00175     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a39219ac00a0e8ed843ee32b9df8be11e">slave_latency</a>     = <a class="code" href="group__ble__sdk__app__template__main.html#ga0c921a874ac37870fc1516ce66cd228a">SLAVE_LATENCY</a>;
<a name="l00176"></a>00176     gap_conn_params.<a class="code" href="structble__gap__conn__params__t.html#a2089e7fb26f6b24882d1437eb5553bc7">conn_sup_timeout</a>  = <a class="code" href="group__ble__sdk__app__template__main.html#ga799412c2b531ca347e13611e6e7523b9">CONN_SUP_TIMEOUT</a>;
<a name="l00177"></a>00177 
<a name="l00178"></a>00178     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga28e0062141d77d7b2272fc3a6b6e17c5" title="Set GAP Peripheral Preferred Connection Parameters.">ble_gap_ppcp_set</a>(&amp;gap_conn_params);
<a name="l00179"></a>00179     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00180"></a>00180     {
<a name="l00181"></a>00181         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00182"></a>00182     }
<a name="l00183"></a>00183 }
<a name="l00184"></a>00184 
<a name="l00185"></a>00185 
<a name="l00191"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga935c9624de0709fe228dbefa4b54de48">00191</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>(<span class="keywordtype">void</span>)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193     uint32_t      err_code;
<a name="l00194"></a>00194     <a class="code" href="structble__advdata__t.html" title="Advertising data structure. This contains all options and data needed for encoding and setting the ad...">ble_advdata_t</a> advdata;
<a name="l00195"></a>00195     uint8_t       flags = <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga5c5243da93bae524088eefd608656012">BLE_GAP_DISC_MODE_LIMITED</a> | <a class="code" href="group___b_l_e___g_a_p___d_i_s_c___m_o_d_e_s.html#ga346a5b47f4b8f94a08f320a0d8c14c18">BLE_GAP_DISC_BR_EDR_NOT_SUPPORTED</a>;
<a name="l00196"></a>00196     
<a name="l00197"></a>00197     <span class="comment">// YOUR_JOB: Use UUIDs for service(s) used in your application.</span>
<a name="l00198"></a>00198     <a class="code" href="structble__uuid__t.html" title="Bluetooth Low Energy UUID type, encapsulates both 16-bit and 128-bit UUIDs.">ble_uuid_t</a> adv_uuids[] = {{<a class="code" href="group___u_u_i_d___s_e_r_v_i_c_e_s.html#ga4090520f3007fe6f90f06a6f4f8d5845">BLE_UUID_BATTERY_SERVICE</a>, <a class="code" href="group___b_l_e___u_u_i_d___t_y_p_e_s.html#gae549d14b15783ba52dae5fdd5f9ac959">BLE_UUID_TYPE_BLE</a>}};
<a name="l00199"></a>00199 
<a name="l00200"></a>00200     <span class="comment">// Build and set advertising data</span>
<a name="l00201"></a>00201     memset(&amp;advdata, 0, <span class="keyword">sizeof</span>(advdata));
<a name="l00202"></a>00202     
<a name="l00203"></a>00203     advdata.<a class="code" href="structble__advdata__t.html#a045ec5915c094e107ac24d185b83fa49">name_type</a>               = <a class="code" href="group__ble__sdk__lib__advdata.html#gga03c5ccf232779001be9786021b1a563ba63a26e22b9d6a0899edac755d0e2f488">BLE_ADVDATA_FULL_NAME</a>;
<a name="l00204"></a>00204     advdata.<a class="code" href="structble__advdata__t.html#aff2bb3e4016b9a7b6cbcdd6e98feb719">include_appearance</a>      = <span class="keyword">true</span>;
<a name="l00205"></a>00205     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#aaba88b24a21a6c70c895c0d55f4a69a0">size</a>              = <span class="keyword">sizeof</span>(flags);
<a name="l00206"></a>00206     advdata.<a class="code" href="structble__advdata__t.html#a3ad6b2c5a983e0f2676c85c546ed47ae">flags</a>.<a class="code" href="structuint8__array__t.html#a8304c4af5da6e830b86d7199dc9a22e6">p_data</a>            = &amp;flags;
<a name="l00207"></a>00207     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a1cecc52d144b939f33a67c1d68363e99">uuid_cnt</a> = <span class="keyword">sizeof</span>(adv_uuids) / <span class="keyword">sizeof</span>(adv_uuids[0]);
<a name="l00208"></a>00208     advdata.<a class="code" href="structble__advdata__t.html#af848e0d7e7334a53498e1e6c592fed90">uuids_complete</a>.<a class="code" href="structble__advdata__uuid__list__t.html#a100265d2ed10e66a76e53cba205dc8a3">p_uuids</a>  = adv_uuids;
<a name="l00209"></a>00209     
<a name="l00210"></a>00210     err_code = <a class="code" href="group__ble__sdk__lib__advdata.html#ga180ff4057a0763688c734e98ab8d976b" title="Encodes and sets the advertising data and/or scan response data.">ble_advdata_set</a>(&amp;advdata, NULL);
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00212"></a>00212     {
<a name="l00213"></a>00213         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00214"></a>00214     }
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 
<a name="l00217"></a>00217 
<a name="l00220"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2">00220</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>(<span class="keywordtype">void</span>)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222     <span class="comment">// YOUR_JOB: Add code to initialize the services used by the application.</span>
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 
<a name="l00225"></a>00225 
<a name="l00228"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga9f11118fb9ce22ad1afe20af6f89b131">00228</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00229"></a>00229 {
<a name="l00230"></a>00230     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>      = <a class="code" href="group__ble__sdk__app__template__main.html#ga7c1fffb0f865552108560d4c63b32db1">SEC_PARAM_TIMEOUT</a>;
<a name="l00231"></a>00231     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a3d9eee3a6a1d710b0e5d13b567675694">bond</a>         = <a class="code" href="group__ble__sdk__app__template__main.html#gacbf03a82593c273743a5a80a1119b851">SEC_PARAM_BOND</a>;
<a name="l00232"></a>00232     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a808e5ec85cf1656a05a985386ba29276">mitm</a>         = <a class="code" href="group__ble__sdk__app__template__main.html#gab6831ebe113f8afe970326b7742b5947">SEC_PARAM_MITM</a>;
<a name="l00233"></a>00233     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a81d248b843331e8798478feecf4f4c92">io_caps</a>      = <a class="code" href="group__ble__sdk__app__template__main.html#ga42df85b3a4083cdc614d9111d580d98f">SEC_PARAM_IO_CAPABILITIES</a>;
<a name="l00234"></a>00234     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a01318f39f3b3471bd44bf2f322331788">oob</a>          = <a class="code" href="group__ble__sdk__app__template__main.html#gaee13a0d0077f423fa0edd74e17fb6b88">SEC_PARAM_OOB</a>;  
<a name="l00235"></a>00235     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a66c3e526aae4ca7f3212ae207225b0a2">min_key_size</a> = <a class="code" href="group__ble__sdk__app__template__main.html#ga6b7b2e2f67fbf790f55b46f8f5e24ad5">SEC_PARAM_MIN_KEY_SIZE</a>;
<a name="l00236"></a>00236     <a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>.<a class="code" href="structble__gap__sec__params__t.html#a43d814618fbf7f63a318966dd84746c2">max_key_size</a> = <a class="code" href="group__ble__sdk__app__template__main.html#gaf2cd1595de153ea1d6d843619a1a7707">SEC_PARAM_MAX_KEY_SIZE</a>;
<a name="l00237"></a>00237 }
<a name="l00238"></a>00238 
<a name="l00239"></a>00239 
<a name="l00250"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga3518a4402961dbde9a52c7de6211ad7a">00250</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga3518a4402961dbde9a52c7de6211ad7a" title="Connection Parameters Module handler.">on_conn_params_evt</a>(<a class="code" href="structble__conn__params__evt__t.html" title="Connection Parameters Module event.">ble_conn_params_evt_t</a> * p_evt)
<a name="l00251"></a>00251 {
<a name="l00252"></a>00252     uint32_t err_code;
<a name="l00253"></a>00253     
<a name="l00254"></a>00254     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(p_evt-&gt;<a class="code" href="structble__conn__params__evt__t.html#a43fc16c6c20c00363c03e968c21c08d7">evt_type</a> == <a class="code" href="group__ble__sdk__lib__conn__params.html#ggae819a1b14dbebf447254ec41f644ec42a693314f30d0f73380ae2701d1094179a">BLE_CONN_PARAMS_EVT_FAILED</a>);
<a name="l00255"></a>00255     
<a name="l00256"></a>00256     err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga1b72b0bedcc2ff560582527aee8e6416" title="Disconnect (GAP Link Termination).">ble_gap_disconnect</a>(<a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, BLE_HCI_CONN_INTERVAL_UNACCEPTABLE);
<a name="l00257"></a>00257     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00258"></a>00258     {
<a name="l00259"></a>00259         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00260"></a>00260     }
<a name="l00261"></a>00261 }
<a name="l00262"></a>00262 
<a name="l00263"></a>00263 
<a name="l00268"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa">00268</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>(uint32_t nrf_error)
<a name="l00269"></a>00269 {
<a name="l00270"></a>00270     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00271"></a>00271 }
<a name="l00272"></a>00272 
<a name="l00273"></a>00273 
<a name="l00276"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaf61b6c1c47f5c96b169ff81c345d7849">00276</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>(<span class="keywordtype">void</span>)
<a name="l00277"></a>00277 {
<a name="l00278"></a>00278     uint32_t               err_code;
<a name="l00279"></a>00279     <a class="code" href="structble__conn__params__init__t.html" title="Connection Parameters Module init structure. This contains all options and data needed for initializa...">ble_conn_params_init_t</a> cp_init;
<a name="l00280"></a>00280     
<a name="l00281"></a>00281     memset(&amp;cp_init, 0, <span class="keyword">sizeof</span>(cp_init));
<a name="l00282"></a>00282 
<a name="l00283"></a>00283     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab211e40857ee8019c8fd5eabfcc12ce7">p_conn_params</a>                  = NULL;
<a name="l00284"></a>00284     cp_init.<a class="code" href="structble__conn__params__init__t.html#a915702f42f9a0316745403644d385f22">first_conn_params_update_delay</a> = <a class="code" href="group__ble__sdk__app__template__main.html#ga7204f7a367e8f1ac53ef62c4ad220efc">FIRST_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00285"></a>00285     cp_init.<a class="code" href="structble__conn__params__init__t.html#a9bcd0621fbb5f4554f1fafd0b15dc61b">next_conn_params_update_delay</a>  = <a class="code" href="group__ble__sdk__app__template__main.html#gadf85796ef07632ed27e0bce9509d9245">NEXT_CONN_PARAMS_UPDATE_DELAY</a>;
<a name="l00286"></a>00286     cp_init.<a class="code" href="structble__conn__params__init__t.html#ab3c0944561623d4a8da622b18867aafb">max_conn_params_update_count</a>   = <a class="code" href="group__ble__sdk__app__template__main.html#ga34db81384bfbef23dedbef9bc6dfe46c">MAX_CONN_PARAMS_UPDATE_COUNT</a>;
<a name="l00287"></a>00287     cp_init.<a class="code" href="structble__conn__params__init__t.html#a6f0b0ef22161b61ba5cc0a7fd3ddedd9">start_on_notify_cccd_handle</a>    = <a class="code" href="group___b_l_e___g_a_t_t_s.html#gaa16a29908fc63343706f56913be51ec1" title="Invalid Attribute Handle.">BLE_GATTS_HANDLE_INVALID</a>;
<a name="l00288"></a>00288     cp_init.<a class="code" href="structble__conn__params__init__t.html#a7a3f3aac03305ef8012ade05399b5449">disconnect_on_fail</a>             = <span class="keyword">false</span>;
<a name="l00289"></a>00289     cp_init.<a class="code" href="structble__conn__params__init__t.html#af6344191be6d1f66ec79d6086def25f1">evt_handler</a>                    = <a class="code" href="group__ble__sdk__app__template__main.html#ga3518a4402961dbde9a52c7de6211ad7a" title="Connection Parameters Module handler.">on_conn_params_evt</a>;
<a name="l00290"></a>00290     cp_init.<a class="code" href="structble__conn__params__init__t.html#a893a7b5845beb42d9e5b650fd012f7f1">error_handler</a>                  = <a class="code" href="group__ble__sdk__app__template__main.html#ga4538ed130db3bf7fc68b76a4d9e032fa" title="Connection Parameters module error handler.">conn_params_error_handler</a>;
<a name="l00291"></a>00291     
<a name="l00292"></a>00292     err_code = <a class="code" href="group__ble__sdk__lib__conn__params.html#gacd9789a0a4c90cfea2ba2656f6408080" title="Initialize the Connection Parameters module.">ble_conn_params_init</a>(&amp;cp_init);
<a name="l00293"></a>00293     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00294"></a>00294     {
<a name="l00295"></a>00295         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00296"></a>00296     }
<a name="l00297"></a>00297 }
<a name="l00298"></a>00298 
<a name="l00299"></a>00299 
<a name="l00302"></a><a class="code" href="group__ble__sdk__app__template__main.html#gab7e1400dcd1b0f9470d20af86077ba74">00302</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gab7e1400dcd1b0f9470d20af86077ba74" title="Start timers.">timers_start</a>(<span class="keywordtype">void</span>)
<a name="l00303"></a>00303 {
<a name="l00304"></a>00304     <span class="comment">/* YOUR_JOB: Start your timers. below is an example of how to start a timer.</span>
<a name="l00305"></a>00305 <span class="comment">    uint32_t err_code;</span>
<a name="l00306"></a>00306 <span class="comment">    </span>
<a name="l00307"></a>00307 <span class="comment">    err_code = app_timer_start(APP_TIMER_ID, </span>
<a name="l00308"></a>00308 <span class="comment">                               timer_timeout_handler, </span>
<a name="l00309"></a>00309 <span class="comment">                               TIMER_INTERVAL, </span>
<a name="l00310"></a>00310 <span class="comment">                               APP_TIMER_MODE_REPEATED/APP_TIMER_MODE_SINGLE_SHOT, </span>
<a name="l00311"></a>00311 <span class="comment">                               APP_SCHED_QUEUE_LOW_PRI);</span>
<a name="l00312"></a>00312 <span class="comment">    if (err_code != NRF_SUCCESS)</span>
<a name="l00313"></a>00313 <span class="comment">    {</span>
<a name="l00314"></a>00314 <span class="comment">        ASSERT(false);</span>
<a name="l00315"></a>00315 <span class="comment">    } */</span>
<a name="l00316"></a>00316 }
<a name="l00317"></a>00317 
<a name="l00318"></a>00318 
<a name="l00321"></a><a class="code" href="group__ble__sdk__app__template__main.html#gadf80cd84ee702e57a2a416fe4f653eb8">00321</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>(<span class="keywordtype">void</span>)
<a name="l00322"></a>00322 {
<a name="l00323"></a>00323     uint32_t             err_code;
<a name="l00324"></a>00324     <a class="code" href="structble__gap__adv__params__t.html" title="GAP advertising parameters.">ble_gap_adv_params_t</a> adv_params;
<a name="l00325"></a>00325     
<a name="l00326"></a>00326     <span class="comment">// Start advertising</span>
<a name="l00327"></a>00327     memset(&amp;adv_params, 0, <span class="keyword">sizeof</span>(adv_params));
<a name="l00328"></a>00328     
<a name="l00329"></a>00329     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a1d127017fb298b889f4ba24752d08b8e">type</a>        = <a class="code" href="group___b_l_e___g_a_p___a_d_v___t_y_p_e_s.html#ga6cc0db53453977ee0a31e59f07de2b86">BLE_GAP_ADV_TYPE_ADV_IND</a>;
<a name="l00330"></a>00330     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a27909d1b865548f236a871af2b6aa584">p_peer_addr</a> = NULL;
<a name="l00331"></a>00331     adv_params.<a class="code" href="structble__gap__adv__params__t.html#aefdab55ee0f22565a03a14d09cc71d12">fp</a>          = <a class="code" href="group___b_l_e___g_a_p___a_d_v___f_i_l_t_e_r___p_o_l_i_c_i_e_s.html#ga0b0393df73db101d6cbfaede2dbb7ea6">BLE_GAP_ADV_FP_ANY</a>;
<a name="l00332"></a>00332     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a6c52a3d605c056768b59164ce8df8334">interval</a>    = <a class="code" href="group__ble__sdk__app__template__main.html#gadde0b932e57e128e4cd81c2dca47cfe3">APP_ADV_INTERVAL</a>;
<a name="l00333"></a>00333     adv_params.<a class="code" href="structble__gap__adv__params__t.html#a7f1ad43d3bf79b40bc39dbb5a6c3a5ae">timeout</a>     = <a class="code" href="group__ble__sdk__app__template__main.html#gaf58371bad8e1be8e2323df60379ed2df">APP_ADV_TIMEOUT_IN_SECONDS</a>;
<a name="l00334"></a>00334 
<a name="l00335"></a>00335     err_code = <a class="code" href="group___b_l_e___g_a_p.html#gabdbf78c3a8b09c6f2fb92d8733096af8" title="Start advertising (GAP Discoverable, Connectable modes, Broadcast Procedure).">ble_gap_adv_start</a>(&amp;adv_params);
<a name="l00336"></a>00336     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00337"></a>00337     {
<a name="l00338"></a>00338         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00339"></a>00339     }
<a name="l00340"></a>00340     <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(ADVERTISING_LED_PIN_NO);
<a name="l00341"></a>00341 }
<a name="l00342"></a>00342 
<a name="l00343"></a>00343 
<a name="l00348"></a><a class="code" href="group__ble__sdk__app__template__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9">00348</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00349"></a>00349 {
<a name="l00350"></a>00350     uint32_t                         err_code = <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>;
<a name="l00351"></a>00351     <span class="keyword">static</span> <a class="code" href="structble__gap__evt__auth__status__t.html" title="Event data for authentication status event.">ble_gap_evt_auth_status_t</a> s_auth_status;
<a name="l00352"></a>00352     <a class="code" href="structble__gap__enc__info__t.html" title="GAP Encryption Information.">ble_gap_enc_info_t</a> *             p_enc_info;
<a name="l00353"></a>00353     
<a name="l00354"></a>00354     <span class="keywordflow">switch</span> (p_ble_evt-&gt;<a class="code" href="structble__evt__t.html#a50f33abba5627a26728ba30fffd9880a">header</a>.<a class="code" href="structble__evt__hdr__t.html#a826314e7ea25d4267621899efe6859f9">evt_id</a>)
<a name="l00355"></a>00355     {
<a name="l00356"></a>00356         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daa0b4789724d202a13a5e7eab85c52957">BLE_GAP_EVT_CONNECTED</a>:
<a name="l00357"></a>00357             <a class="code" href="group__nrf__gpio.html#gacaf7e8e242a47f7b635bbeca5c5934a3" title="Set GPIO pin.">nrf_gpio_pin_set</a>(CONNECTED_LED_PIN_NO);
<a name="l00358"></a>00358             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00359"></a>00359             <a class="code" href="group__app__timer.html#ga4112ddbc75deb5c4d5db7c8afb1f5d8a" title="Stops the specified timer.">app_timer_stop</a>(APP_TIMER_STOP_ADVERTISE);
<a name="l00360"></a>00360             <a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a91857ca158f0c4e43f610068772c7d3d">gatts_evt</a>.<a class="code" href="structble__gatts__evt__t.html#a0d5ffe38d68e48d81e61fc6a4999ae68">conn_handle</a>;
<a name="l00361"></a>00361             <span class="keywordflow">break</span>;
<a name="l00362"></a>00362             
<a name="l00363"></a>00363         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da057001bbd6ea9e615f19ef93cc0831ee">BLE_GAP_EVT_DISCONNECTED</a>:
<a name="l00364"></a>00364             <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(CONNECTED_LED_PIN_NO);
<a name="l00365"></a>00365             <a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a> = <a class="code" href="group___b_l_e___c_o_n_n___h_a_n_d_l_e_s.html#gacf227b9b101dbcf08eccbbaba54e48f5">BLE_CONN_HANDLE_INVALID</a>;
<a name="l00366"></a>00366             <a class="code" href="group__ble__sdk__app__template__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l00367"></a>00367             <span class="keywordflow">break</span>;
<a name="l00368"></a>00368             
<a name="l00369"></a>00369         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da6c5eefbcfabbc1ce4a8bcbf550c285ae">BLE_GAP_EVT_SEC_PARAMS_REQUEST</a>:
<a name="l00370"></a>00370             err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga5339c2562371354a0e3752b86214b92a" title="Reply with GAP security parameters.">ble_gap_sec_params_reply</a>(<a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, 
<a name="l00371"></a>00371                                                 <a class="code" href="group___b_l_e___g_a_p___s_e_c___s_t_a_t_u_s.html#gaa0334dea24e449e5c28c88bbe8a1d00f">BLE_GAP_SEC_STATUS_SUCCESS</a>, 
<a name="l00372"></a>00372                                                 &amp;<a class="code" href="group__ble__sdk__app__template__main.html#ga738ed84e141ba1059dd1318dc425343c">s_sec_params</a>);
<a name="l00373"></a>00373             <span class="keywordflow">break</span>;
<a name="l00374"></a>00374             
<a name="l00375"></a>00375         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_t_t_s.html#gga80155586fa275b28773c9b203f52cabaae3776204f11a583e105aed0e477601da">BLE_GATTS_EVT_SYS_ATTR_MISSING</a>:
<a name="l00376"></a>00376             err_code = <a class="code" href="group___b_l_e___g_a_t_t_s.html#ga65ae169e49530eb2fa4bf73053060a13" title="Update persistent system attribute info.">ble_gatts_sys_attr_set</a>(<a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, NULL, 0);
<a name="l00377"></a>00377             <span class="keywordflow">break</span>;
<a name="l00378"></a>00378 
<a name="l00379"></a>00379         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da8958220152f7547da3b250b4f724877c">BLE_GAP_EVT_AUTH_STATUS</a>:
<a name="l00380"></a>00380             s_auth_status = p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a350f0c3a127499fb3d522d361554e3eb">auth_status</a>;
<a name="l00381"></a>00381             <span class="keywordflow">break</span>;
<a name="l00382"></a>00382             
<a name="l00383"></a>00383         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035daf1c60079f92820cb933ebdb66d2d8d7d">BLE_GAP_EVT_SEC_INFO_REQUEST</a>:
<a name="l00384"></a>00384             p_enc_info = &amp;s_auth_status.periph_keys.<a class="code" href="structble__gap__evt__auth__status__t_1_1periph__keys__t.html#a7eee7ec3b96cc86a0080ab368dae817d">enc_info</a>;
<a name="l00385"></a>00385             <span class="keywordflow">if</span> (p_enc_info-&gt;<a class="code" href="structble__gap__enc__info__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a> == p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a5f04f763d053c94297246b6ed351c66a">sec_info_request</a>.<a class="code" href="structble__gap__evt__sec__info__request__t.html#aa1147a1ab6ff4c36934461ca71d73bef">div</a>)
<a name="l00386"></a>00386             {
<a name="l00387"></a>00387                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(<a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, p_enc_info, NULL);
<a name="l00388"></a>00388             }
<a name="l00389"></a>00389             <span class="keywordflow">else</span>
<a name="l00390"></a>00390             {
<a name="l00391"></a>00391                 <span class="comment">// No keys found for this device</span>
<a name="l00392"></a>00392                 err_code = <a class="code" href="group___b_l_e___g_a_p.html#ga31de499e23c1d7876612af2fa65f3c46" title="Reply with GAP security information.">ble_gap_sec_info_reply</a>(<a class="code" href="group__ble__sdk__app__template__main.html#gaaf76d22968f9f320aa5005a25f654320">s_conn_handle</a>, NULL, NULL);
<a name="l00393"></a>00393             }
<a name="l00394"></a>00394             <span class="keywordflow">break</span>;
<a name="l00395"></a>00395 
<a name="l00396"></a>00396         <span class="keywordflow">case</span> <a class="code" href="group___b_l_e___g_a_p.html#ggabc5c98fcc1211af2b80116dd6e0a035da57e5d1061d9b3d1500fb3556a3fb8847">BLE_GAP_EVT_TIMEOUT</a>:
<a name="l00397"></a>00397             <span class="keywordflow">if</span> (p_ble_evt-&gt;evt.<a class="code" href="structble__evt__t.html#a2fd98f8868b9aea30d35bf71d41d646a">gap_evt</a>.params.<a class="code" href="structble__gap__evt__t.html#a17e289da592e731cde1451c2d5f3f24a">timeout</a>.<a class="code" href="structble__gap__evt__timeout__t.html#af5eca485cd2b34522478907d4c8f5bc6">src</a> == <a class="code" href="group___b_l_e___g_a_p___t_i_m_e_o_u_t___t_y_p_e_s.html#gafee7b7095fb21ed922c6719cc1c2d23f">BLE_GAP_TIMEOUT_TYPE_ADVERTISEMENT</a>)
<a name="l00398"></a>00398             { 
<a name="l00399"></a>00399                 <a class="code" href="group__nrf__gpio.html#gaf3de3729249d55592c86ecfa97fb9347" title="Clear GPIO pin.">nrf_gpio_pin_clear</a>(ADVERTISING_LED_PIN_NO);
<a name="l00400"></a>00400 
<a name="l00401"></a>00401                 <span class="comment">// Go to system-off mode (this function will not return; wakeup will cause a reset)</span>
<a name="l00402"></a>00402                 err_code = <a class="code" href="group__nrf__soc__api.html#ga302701614c7bb1c9fc01dafec2bb04fb" title="Puts the chip in System OFF mode.">nrf_power_system_off</a>();    
<a name="l00403"></a>00403             }
<a name="l00404"></a>00404             <span class="keywordflow">break</span>;
<a name="l00405"></a>00405 
<a name="l00406"></a>00406         <span class="keywordflow">default</span>:
<a name="l00407"></a>00407             <span class="keywordflow">break</span>;
<a name="l00408"></a>00408     }
<a name="l00409"></a>00409 
<a name="l00410"></a>00410     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00411"></a>00411     {
<a name="l00412"></a>00412         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00413"></a>00413     }
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 
<a name="l00416"></a>00416 
<a name="l00424"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d">00424</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>(app_sched_event_data_t * p_ev_data)
<a name="l00425"></a>00425 {
<a name="l00426"></a>00426     <a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt;
<a name="l00427"></a>00427     
<a name="l00428"></a>00428     <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(p_ev_data-&gt;event_id == APP_SCHED_EVENT_BLE);
<a name="l00429"></a>00429     
<a name="l00430"></a>00430     p_ble_evt = &amp;p_ev_data-&gt;data.ble.ble_evt;
<a name="l00431"></a>00431 
<a name="l00432"></a>00432     <a class="code" href="group__ble__sdk__app__template__main.html#gad083cb3569230d7ecbf2d01ef2a2c1d9" title="Application&#39;s BLE Stack event handler.">on_ble_evt</a>(p_ble_evt);
<a name="l00433"></a>00433     <a class="code" href="group__ble__sdk__lib__conn__params.html#gadef0873bee110db3da8b77f801177871" title="BLE stack event handler.">ble_conn_params_on_ble_evt</a>(p_ble_evt);
<a name="l00434"></a>00434     <span class="comment">/* </span>
<a name="l00435"></a>00435 <span class="comment">    YOUR_JOB: Add service ble_evt handlers calls here, like, for example:</span>
<a name="l00436"></a>00436 <span class="comment">    ble_bas_on_ble_evt(&amp;s_bas, p_ble_evt);</span>
<a name="l00437"></a>00437 <span class="comment">    */</span>
<a name="l00438"></a>00438 }
<a name="l00439"></a>00439 
<a name="l00440"></a>00440 
<a name="l00448"></a><a class="code" href="group__ble__sdk__app__template__main.html#gacf1716b2e00b3456f0733e8101ed9e0d">00448</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gacf1716b2e00b3456f0733e8101ed9e0d" title="Pass bluetooth stack event to scheduler.">ble_evt_schedule</a>(<a class="code" href="structble__evt__t.html" title="Common BLE Event type, wrapping the module specific event reports.">ble_evt_t</a> * p_ble_evt)
<a name="l00449"></a>00449 {
<a name="l00450"></a>00450     uint32_t               err_code;
<a name="l00451"></a>00451     app_sched_event_data_t ev_data;
<a name="l00452"></a>00452     
<a name="l00453"></a>00453     ev_data.event_id         = APP_SCHED_EVENT_BLE;
<a name="l00454"></a>00454     ev_data.data.ble.ble_evt = *p_ble_evt;
<a name="l00455"></a>00455     
<a name="l00456"></a>00456     err_code = <a class="code" href="group__app__scheduler.html#gaaecab81ed0f2e9c1ce56586367b93dc5" title="Schedules an event.">app_sched_event_put</a>(&amp;ev_data, <a class="code" href="group__ble__sdk__app__template__main.html#gaa1927dfd1c321164f2f34ae9ad95a77d" title="Dispatches a BLE stack event to all modules with a BLE stack event handler.">ble_evt_dispatch</a>, APP_SCHED_QUEUE_LOW_PRI);
<a name="l00457"></a>00457     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00458"></a>00458     {
<a name="l00459"></a>00459         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00460"></a>00460     }
<a name="l00461"></a>00461 }
<a name="l00462"></a>00462 
<a name="l00463"></a>00463 
<a name="l00468"></a><a class="code" href="group__ble__sdk__app__template__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a">00468</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>(<span class="keywordtype">void</span>)
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470     uint32_t err_code = <a class="code" href="group__ble__stack__handler.html#gada9282a45a226bbe8544995b2fbf22dd" title="Initialize stack handler module.">ble_stack_handler_init</a>(<a class="code" href="group__nrf__sdm__api.html#ggaaf8fd5f0e57d456151c951e0f3715fc4a1c5e9917211a50eac336a3fd2e467756">NRF_CLOCK_LFCLKSRC_XTAL_20_PPM</a>, <a class="code" href="group__ble__sdk__app__template__main.html#gacf1716b2e00b3456f0733e8101ed9e0d" title="Pass bluetooth stack event to scheduler.">ble_evt_schedule</a>);
<a name="l00471"></a>00471     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00472"></a>00472     {
<a name="l00473"></a>00473         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00474"></a>00474     }
<a name="l00475"></a>00475 }
<a name="l00476"></a>00476 
<a name="l00477"></a>00477 
<a name="l00480"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga26b108e2296d5514a2391960b4231d71">00480</a> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga26b108e2296d5514a2391960b4231d71" title="GPIOTE interrupt handler.">GPIOTE_IRQHandler</a>(<span class="keywordtype">void</span>)
<a name="l00481"></a>00481 {
<a name="l00482"></a>00482   <span class="comment">// YOUR_JOB: Add code to detect which IO has generated the interrupt and forward the corresponding</span>
<a name="l00483"></a>00483   <span class="comment">//           event to the scheduler or handle it in any other way. Refer to the example </span>
<a name="l00484"></a>00484   <span class="comment">//           applications to see how the code here may look like.</span>
<a name="l00485"></a>00485 }
<a name="l00486"></a>00486 
<a name="l00487"></a>00487 
<a name="l00490"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga265c25c068555fbfae4ab4f391060040">00490</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>(<span class="keywordtype">void</span>)
<a name="l00491"></a>00491 {
<a name="l00492"></a>00492     uint32_t err_code;
<a name="l00493"></a>00493     uint32_t per_rdy;
<a name="l00494"></a>00494     
<a name="l00495"></a>00495     <span class="comment">// Power on GPIOTE module</span>
<a name="l00496"></a>00496     err_code = <a class="code" href="group__nrf__soc__api.html#ga4070a6cd178fce204f58a1bf6e3fc954" title="Sets bits in the NRF_POWER-&gt;PERPOWER register.">nrf_power_perpower_set</a>(POWER_PERPOWER_GPIOTE_Msk);
<a name="l00497"></a>00497     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00498"></a>00498     {
<a name="l00499"></a>00499         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00500"></a>00500     }
<a name="l00501"></a>00501 
<a name="l00502"></a>00502     <span class="keywordflow">do</span>
<a name="l00503"></a>00503     {
<a name="l00504"></a>00504         err_code = <a class="code" href="group__nrf__soc__api.html#gabaf2aa42d1d287d9d4fd2b00ecda1da7" title="Get contents of NRF_POWER-&gt;PERRDY register, indicates which peripherals are powered on/off...">nrf_power_perrdy_get</a>(&amp;per_rdy);
<a name="l00505"></a>00505         <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00506"></a>00506         {
<a name="l00507"></a>00507             <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00508"></a>00508         }
<a name="l00509"></a>00509     } <span class="keywordflow">while</span> ((per_rdy &amp; POWER_PERRDY_GPIOTE_Msk) == 0);
<a name="l00510"></a>00510     
<a name="l00511"></a>00511     <span class="comment">// Initialize GPIOTE module</span>
<a name="l00512"></a>00512     NRF_GPIOTE-&gt;INTENCLR = 0xffffffffUL;
<a name="l00513"></a>00513     <span class="comment">/* YOUR_JOB: Uncomment this part if you need to receive PORT event (that occurs during</span>
<a name="l00514"></a>00514 <span class="comment">                 button presses for example). Appropriate handling of the PORT event should be done </span>
<a name="l00515"></a>00515 <span class="comment">                 in GPIOTE_IRQHandler. Refer to the source code of example applications for usage.</span>
<a name="l00516"></a>00516 <span class="comment">    NRF_GPIOTE-&gt;INTENSET = GPIOTE_INTENSET_PORT_Msk;</span>
<a name="l00517"></a>00517 <span class="comment">    */</span>
<a name="l00518"></a>00518     
<a name="l00519"></a>00519     <span class="comment">// Set Button 0 as wakeup source</span>
<a name="l00520"></a>00520     <a class="code" href="group__ble__sdk__lib__util.html#ga6259b9f2ea4ab48312b1836c71f484bb" title="Macro to configure an I/O.">GPIO_PIN_CONFIG</a>(NRF6310_BUTTON_0, 
<a name="l00521"></a>00521                     GPIO_PIN_CNF_DIR_Input, 
<a name="l00522"></a>00522                     GPIO_PIN_CNF_PULL_Disabled, 
<a name="l00523"></a>00523                     GPIO_PIN_CNF_DRIVE_S0S1, 
<a name="l00524"></a>00524                     GPIO_PIN_CNF_SENSE_Low);
<a name="l00525"></a>00525     
<a name="l00526"></a>00526     <span class="comment">// Enable GPIOTE interrupt</span>
<a name="l00527"></a>00527     err_code = <a class="code" href="group__nrf__soc__api.html#ga444796a3a1fc91db087ceebcd92d6561" title="Clear Pending Interrupt.">nrf_nvic_ClearPendingIRQ</a>(GPIOTE_IRQn);
<a name="l00528"></a>00528     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00529"></a>00529     {
<a name="l00530"></a>00530         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00531"></a>00531     }
<a name="l00532"></a>00532     
<a name="l00533"></a>00533     err_code = <a class="code" href="group__nrf__soc__api.html#gad1a939313c86ac881a0b1043715ef475" title="Set Interrupt Priority.">nrf_nvic_SetPriority</a>(GPIOTE_IRQn, NRF_APP_PRIORITY_LOW);
<a name="l00534"></a>00534     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00535"></a>00535     {
<a name="l00536"></a>00536         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00537"></a>00537     }
<a name="l00538"></a>00538     
<a name="l00539"></a>00539     err_code = <a class="code" href="group__nrf__soc__api.html#ga624ecb710ec5cdaf22893608d55c6f3a" title="Enable External Interrupt.">nrf_nvic_EnableIRQ</a>(GPIOTE_IRQn);
<a name="l00540"></a>00540     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00541"></a>00541     {
<a name="l00542"></a>00542         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00543"></a>00543     }
<a name="l00544"></a>00544 }
<a name="l00545"></a>00545 
<a name="l00546"></a>00546 
<a name="l00549"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga3adda2642702fdb99b08992c39494000">00549</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="group__ble__sdk__app__template__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>(<span class="keywordtype">void</span>)
<a name="l00550"></a>00550 {
<a name="l00551"></a>00551     uint32_t err_code = <a class="code" href="group__nrf__soc__api.html#ga2aae5f388f1b6179058c62e2fb05a547" title="Waits for an application event.">nrf_wait_for_app_event</a>();
<a name="l00552"></a>00552     <span class="keywordflow">if</span> (err_code != <a class="code" href="group__nrf__error.html#ga7e6367efeaac363d8cf024940b4ec123" title="Successful command.">NRF_SUCCESS</a>)
<a name="l00553"></a>00553     {
<a name="l00554"></a>00554         <a class="code" href="nrf__assert_8h.html#a28301f76c53b643912da7c538f74e2c6" title="Assert empty when disabled.">ASSERT</a>(<span class="keyword">false</span>);
<a name="l00555"></a>00555     }
<a name="l00556"></a>00556 }
<a name="l00557"></a>00557 
<a name="l00558"></a>00558 
<a name="l00561"></a><a class="code" href="group__ble__sdk__app__template__main.html#ga840291bc02cba5474a4cb46a9b9566fe">00561</a> <span class="keywordtype">int</span> <a class="code" href="group__ble__sdk__app__gzll__main.html#ga840291bc02cba5474a4cb46a9b9566fe" title="Application main function.">main</a>(<span class="keywordtype">void</span>)
<a name="l00562"></a>00562 {
<a name="l00563"></a>00563     <span class="comment">// Initialize</span>
<a name="l00564"></a>00564     <a class="code" href="group__ble__sdk__app__gzll__ui.html#ga67cfc3137a465e560792490e81365254" title="LEDs initialization.">leds_init</a>();
<a name="l00565"></a>00565     <a class="code" href="group__ble__sdk__app__template__main.html#gaa06a7a39e83ec4cf3553f4ed6ba6323a" title="BLE stack initialization.">ble_stack_init</a>();
<a name="l00566"></a>00566     <a class="code" href="group__app__scheduler.html#ga62e8131bc306582c34e1db7565f08a81" title="Initializes the Scheduler.">app_sched_init</a>();
<a name="l00567"></a>00567     <a class="code" href="group__ble__sdk__app__template__main.html#ga09658aaa0774820d8f25249d551bc283" title="Timer initialization.">timers_init</a>();
<a name="l00568"></a>00568     <a class="code" href="group__ble__sdk__app__gzll__ui.html#gacef6dd444cb6560da652897ee43ab306" title="Initialize GPIOTE module for detecting buttons.">buttons_init</a>();
<a name="l00569"></a>00569     <a class="code" href="group__ble__sdk__app__template__main.html#ga1004973353f351806e42896c491a5ab2" title="GAP initialization.">gap_params_init</a>();
<a name="l00570"></a>00570     <a class="code" href="group__ble__sdk__app__template__main.html#ga935c9624de0709fe228dbefa4b54de48" title="Advertising functionality initialization.">advertising_init</a>();
<a name="l00571"></a>00571     <a class="code" href="group__ble__sdk__app__template__main.html#ga5b27b40e18af00d43b92f57eaed0e9b2" title="Initialize services that will be used by the application.">services_init</a>();
<a name="l00572"></a>00572     <a class="code" href="group__ble__sdk__app__template__main.html#gaf61b6c1c47f5c96b169ff81c345d7849" title="Initialize the Connection Parameters module.">conn_params_init</a>();
<a name="l00573"></a>00573     <a class="code" href="group__ble__sdk__app__template__main.html#ga9f11118fb9ce22ad1afe20af6f89b131" title="Initialize security parameters.">sec_params_init</a>();
<a name="l00574"></a>00574     
<a name="l00575"></a>00575     <span class="comment">// Start execution</span>
<a name="l00576"></a>00576     <a class="code" href="group__ble__sdk__app__template__main.html#gab7e1400dcd1b0f9470d20af86077ba74" title="Start timers.">timers_start</a>();
<a name="l00577"></a>00577     <a class="code" href="group__ble__sdk__app__template__main.html#gadf80cd84ee702e57a2a416fe4f653eb8" title="Start advertising.">advertising_start</a>();
<a name="l00578"></a>00578     
<a name="l00579"></a>00579     <span class="comment">// Enter main loop</span>
<a name="l00580"></a>00580     <span class="keywordflow">for</span> (;;)
<a name="l00581"></a>00581     {
<a name="l00582"></a>00582         <a class="code" href="group__app__scheduler.html#ga6fd6a3db7526418f796c55c096360ded" title="Executes all scheduled events.">app_sched_schedule</a>();
<a name="l00583"></a>00583         <a class="code" href="group__ble__sdk__app__template__main.html#ga3adda2642702fdb99b08992c39494000" title="Power manager.">power_manage</a>();
<a name="l00584"></a>00584     }
<a name="l00585"></a>00585 }
<a name="l00586"></a>00586 
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="nrf6310__nrf2752_2ble_2ble__app__template_2main_8c.html">main.c</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
      Copyright &copy 2006-2011 <a href="http://www.nordicsemi.no" style="text-decoration:none">Nordic Semiconductor</a>.
      All Rights Reserved.
      <a href="disclaimer.html">Disclaimer</a>
    </li>
   </ul>
 </div>


</body>
</html>
